<template>
  <div :class="className" :style="{height:height,width:width}"></div>
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons') // echarts theme
  import resize from './mixins/resize'
  export default {
    name: "LineChart2",
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '350px'
      }
      // autoResize: {
      //   type: Boolean,
      //   default: true
      // },
      // chartData: {
      //   type: Object,
      //   required: true
      // }
    },
    data() {
      return {
        chart: null,
        colors: [
          '#BE4432',
          '#4D3D4E',
          '#485B55',
          '#293742'
        ]
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.chart = echarts.init(this.$el, 'macarons')
        this.setOptions(this.chartData)
      },
      // eslint-disable-next-line no-unused-vars
      setOptions({ expectedData, actualData } = {}){
        this.chart.setOption({
          color: this.colors,
          backgroundColor: 'transparent',
          // title: {
          //   text: '数据日记',
          //   textStyle: {
          //     color: '#333333',
          //     fontSize: 24,
          //     lineHeight: 28,
          //     fontWeight: 'bolder'
          //   }
          // },
          tooltip: {
            trigger: 'axis'
          },
          legend: {
            data: ['入库数据', '待清理数据'],
            // orient: 'vertical',
            icon: "roundRect",
            itemWidth: 40,
            itemHeight: 20,
            left: 10,
            top: 10
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          feature: {
            mark: {show: true}
          },
          xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ['2020.7', '2020.10','2021.1', '2021.4', '2021.7', '2021.10']
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              name: '入库数据',
              type: 'line',
              //stack: 'Total',
              data: [0, 0, 16000, 16000,16000, 30000]
            },
            {
              name: '待清理数据',
              type: 'line',
              //stack: 'Total',
              data: [22000, 22000, 6000,6000, 50000, 40000]
            }
          ]
        })
      }
    }
  }
</script>

<style scoped>

</style>